<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1x509.js' X509Util.newCert verifySignature test</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/cj/cryptojs-312-core-fix.js"></script>
<script src="../ext/cj/x64-core.js"></script>
<script src="../ext/cj/cipher-core_min.js"></script>
<script src="../ext/cj/aes_min.js"></script>
<script src="../ext/cj/tripledes_min.js"></script>
<script src="../ext/cj/enc-base64_min.js"></script>
<script src="../ext/cj/md5_min.js"></script>
<script src="../ext/cj/sha1_min.js"></script>
<script src="../ext/cj/sha256_min.js"></script>
<script src="../ext/cj/sha224_min.js"></script>
<script src="../ext/cj/sha512_min.js"></script>
<script src="../ext/cj/sha384_min.js"></script>
<script src="../ext/cj/ripemd160_min.js"></script>
<script src="../ext/cj/hmac_min.js"></script>
<script src="../ext/cj/pbkdf2_min.js"></script>

<script src="../ext/yahoo.js"></script>
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/base64.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/ec.js"></script>
<script src="../ext/ec-patch.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/rsapem-1.1.js"></script>
<script src="../src/rsasign-1.2.js"></script>
<script src="../src/crypto-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/ecdsa-modified-1.0.js"></script>
<script src="../src/ecparam-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script src="../src/x509-1.1.js"></script>
<script src="../src/keyutil-1.0.js"></script>

<script type="text/javascript">
<!--
// *** DATA *********************
var certTmpl = {
   serial: {int: 4},
   sigalg: {name: 'SHA1withRSA'},
   issuer: {str: '/C=US/O=a'},
   notbefore: {str: '130504235959Z'},
   notafter: {str: '140504235959Z'},
   subject: {str: '/C=US/O=b'},
   sbjpubkey: null,
   ext: [
     {basicConstraints: {cA: true, critical: true}},
     {keyUsage: {bin: '11'}},
     {cRLDistributionPoints: {uri: 'http://aaa.com/a.crl'}},
     {extKeyUsage: {array: [{name: 'clientAuth'}]}},
   ],
   cakey: null
};

var kpRSA = KEYUTIL.generateKeypair("RSA", 1024);
var kpEC =  KEYUTIL.generateKeypair("EC", "secp256k1");

// *** TEST *********************
$(document).ready(function(){

test("newCertPEM SHA1withRSA signature value verify", function() {
var tmpl = JSON.parse(JSON.stringify(certTmpl));
tmpl.sigalg.name = "SHA1withRSA";
tmpl.sbjpubkey = kpRSA.pubKeyObj;
tmpl.cakey = kpRSA.prvKeyObj;
var certPEM = KJUR.asn1.x509.X509Util.newCertPEM(tmpl);
var hCert = pemtohex(certPEM);
var x = new X509();
x.readCertHex(hCert);
equal(x.verifySignature(kpRSA.pubKeyObj), true, "VALID");
});

test("newCertPEM SHA256withRSA signature value verify", function() {
var tmpl = JSON.parse(JSON.stringify(certTmpl));
tmpl.sigalg.name = "SHA256withRSA";
tmpl.sbjpubkey = kpRSA.pubKeyObj;
tmpl.cakey = kpRSA.prvKeyObj;
var certPEM = KJUR.asn1.x509.X509Util.newCertPEM(tmpl);
var hCert = pemtohex(certPEM);
var x = new X509();
x.readCertHex(hCert);
equal(x.verifySignature(kpRSA.pubKeyObj), true, "VALID");
});

test("newCertPEM SHA1withECDSA signature value verify", function() {
var tmpl = JSON.parse(JSON.stringify(certTmpl));
tmpl.sigalg.name = "SHA1withECDSA";
tmpl.sbjpubkey = kpEC.pubKeyObj;
tmpl.cakey = kpEC.prvKeyObj;
var certPEM = KJUR.asn1.x509.X509Util.newCertPEM(tmpl);
var hCert = pemtohex(certPEM);
var x = new X509();
x.readCertHex(hCert);
equal(x.verifySignature(kpEC.pubKeyObj), true, "VALID");
});

test("newCertPEM SHA256withECDSA signature value verify", function() {
var tmpl = JSON.parse(JSON.stringify(certTmpl));
tmpl.sigalg.name = "SHA256withECDSA";
tmpl.sbjpubkey = kpEC.pubKeyObj;
tmpl.cakey = kpEC.prvKeyObj;
var certPEM = KJUR.asn1.x509.X509Util.newCertPEM(tmpl);
var hCert = pemtohex(certPEM);
var x = new X509();
x.readCertHex(hCert);
equal(x.verifySignature(kpEC.pubKeyObj), true, "VALID");
});

});
-->
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> |
<a href="qunit-do-x509-hex2dn.html">x509-hex2dn</a> |
<a href="qunit-do-asn1x509.html">asn1x509</a> |
<a href="qunit-do-asn1x509-newcrt.html">asn1x509-newcrt</a> |
<a href="qunit-do-asn1x509-multirdn.html">asn1x509-multirdn</a> |
<a href="qunit-do-asn1csr.html">asn1csr</a> |
</body>
</html>
